package com.donglan.pethome.basic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: zhangdonghui
 * @Date: 2021/10/25 18:00
 */
@Configuration //声明该类为配置类
@EnableSwagger2 //声明启动Swagger2
public class SwaggerConfig{
    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //扫描的包路径,为当前包下controller生成API文档
                .apis(RequestHandlerSelectors.basePackage("com.donglan.pethome"))
                // 为有@Api注解的Controller生成API文档
//                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                // 为有@ApiOperation注解的方法生成API文档
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                // 扫描接口的路径，PathSelectors下有四种方法，我们这里是全扫，其他方法我们后续介绍
                .paths(PathSelectors.any())
                .build();
    }

    // 基本信息的配置，信息会在API文档上显示
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("宠物之家")//文档说明
                .version("1.0")//文档版本说明
                .description("提供当前项目所有controller的接口")
                .contact(new Contact("张冬晖", "http://www.donglan.com", "zhangdonghui370@126.com"))
                .build();
    }
}
